#ifndef __MARS_GRAPHICS_VERTEX_DATA_H__
#define __MARS_GRAPHICS_VERTEX_DATA_H__

#include "MarsType.h"

namespace Graphics
{

class VRamBuffer;
class InputLayout;

class VertexData
{
public:
	enum							IndexBufferFormat
	{
		IBF_Unknown = -1,
		IBF_UInt8	= 0,
		IBF_UInt16  = 1,
		IBF_UInt32  = 2,
	};

public:
									VertexData( InputLayout*		pLayout, 
												Core::uint8*		pVertexBuffer,
												Core::uint32		iVertexBufferSize,
												Core::uint8*		pIndexBuffer		= NULL,
												Core::uint32		iIndexBufferSize	= 0,
												IndexBufferFormat	eFormat				= IBF_Unknown,
												bool				bCreateVRamBuffer	= true);
									~VertexData();

	InputLayout*					GetInputLayout();
	VRamBuffer*						GetVertexBuffer();
	VRamBuffer*						GetIndexBuffer();

	DXGI_FORMAT						GetIndexBufferFormat() const;
	bool							IsContainIndexBuffer() const;

private:
	bool							CreateVRamBuffer();
	void							DeleteVRamBuffer();

	VRamBuffer*						m_pVRamVertexBuffer;
	VRamBuffer*						m_pVRamIndexBuffer;
	InputLayout*					m_pInputLayout;
	Core::uint8*					m_pMemVertexBuffer;
	Core::uint32					m_iVertexBufferSize;
	Core::uint8*					m_pMemIndexBuffer;
	Core::uint32					m_iIndexBufferSize;
	IndexBufferFormat				m_eIndexBufferFormat;
};

inline VertexData::VertexData(InputLayout*		pLayout, 
							  Core::uint8*		pVertexBuffer,
							  Core::uint32		iVertexBufferSize,
							  Core::uint8*		pIndexBuffer,
							  Core::uint32		iIndexBufferSize,
							  IndexBufferFormat eFormat,
							  bool				bCreateVRamBuffer)
	: m_pVRamVertexBuffer( NULL )
	, m_pVRamIndexBuffer( NULL )
	, m_pInputLayout( pLayout )
	, m_pMemVertexBuffer( pVertexBuffer )
	, m_iVertexBufferSize( iVertexBufferSize )
	, m_pMemIndexBuffer( pIndexBuffer )
	, m_iIndexBufferSize( iIndexBufferSize )
	, m_eIndexBufferFormat( eFormat )
{
	if ( bCreateVRamBuffer )
		CreateVRamBuffer();
}

inline InputLayout* VertexData::GetInputLayout()
{
	return m_pInputLayout;
}

inline VRamBuffer* VertexData::GetVertexBuffer()
{
	return m_pVRamVertexBuffer;
}

inline VRamBuffer* VertexData::GetIndexBuffer()
{
	return m_pVRamIndexBuffer;
}

inline bool VertexData::IsContainIndexBuffer() const
{
	return ( m_pVRamIndexBuffer != NULL );
}

} // end of namespace Graphics

#endif // end of #ifndef __MARS_GRAPHICS_VERTEX_DATA_H__